package com.ddn.service.room.impl;

import com.ddn.mapper.roomManagement.RoomMapper;
import com.ddn.model.roomManagement.Room;
import com.ddn.model.roomManagement.RoomVO;
import com.ddn.service.room.RoomService;
import com.ddn.util.ResultData;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * --- 天道酬勤 ---
 *
 * @author XieYp
 * @desc
 * @date 2022/12/30
 */
@Service
public class RoomServiceImpl implements RoomService {

    @Autowired
    private RoomMapper roomMapper;

    @Override
    public ResultData findAll(HashMap<String, Object> map) {

        String pageNo = (String) map.get("page");
        String pageSize = (String) map.get("limit");

        PageHelper.startPage(Integer.parseInt(pageNo),Integer.parseInt(pageSize));

        // 查询全部
        List<RoomVO> roomVOS =  roomMapper.findAll(map);



        PageInfo<RoomVO> info = new PageInfo<>( roomVOS );
        // 计数
        return ResultData.ok(roomVOS, (int) info.getTotal());
    }

    @Override
    public ResultData addRoom(Room room) {
        boolean isOk = roomMapper.addRoom(room);
        if (isOk) {
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    @Override
    public ResultData deleteRoom(HashMap<String, Object> map) {
        boolean isOk = roomMapper.deleteRoom(map);
        if (isOk){
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    @Override
    public ResultData updateRoom(HashMap<String, Object> map) {
        boolean isOk = roomMapper.updateRoom(map);
        if (isOk){
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    @Override
    public ResultData deleteBatch(List<Integer> ids) {
        boolean isOk = roomMapper.deleteBatch(ids);
        if (isOk) {
            return ResultData.ok();
        }
        return ResultData.fail();
    }

}
